package com.huang.core.widget.recyclerview.decoration

import android.graphics.Color
import android.view.View
import com.huang.core.widget.recyclerview.decoration.base.Y_Divider
import com.huang.core.widget.recyclerview.decoration.base.Y_DividerBuilder
import com.huang.core.widget.recyclerview.decoration.base.Y_ItemDecoration

class LinearDividerItemDecoration(
        private var orientation: Int,
        private val size: Float = 0.5f,
        private val padding: Float = 0f,
        private val colorInt: Int = Color.parseColor("#dddddd")
) : Y_ItemDecoration() {

    var drawFirstLine = false
    var drawEndLine = false

    override fun getDivider(itemPosition: Int, itemCount: Int, view: View): Y_Divider {
        if (orientation == VERTICAL) {
            if (itemCount == 1) {
                return Y_DividerBuilder()
                        .setTopSideLine(drawFirstLine, colorInt, size, padding, padding)
                        .setBottomSideLine(drawEndLine, colorInt, size, padding, padding)
                        .create()
            } else if (itemPosition == 0) {
                return Y_DividerBuilder()
                        .setTopSideLine(drawFirstLine, colorInt, size, padding, padding)
                        .create()
            } else if (itemPosition < itemCount - 1) {
                return Y_DividerBuilder()
                        .setTopSideLine(true, colorInt, size, padding, padding)
                        .create()
            } else return Y_DividerBuilder()
                    .setTopSideLine(true, colorInt, size, padding, padding)
                    .setBottomSideLine(drawEndLine, colorInt, size, padding, padding)
                    .create()
        } else {
            if (itemCount == 1) {
                return Y_DividerBuilder()
                        .setLeftSideLine(drawFirstLine, colorInt, size, padding, padding)
                        .setRightSideLine(drawEndLine, colorInt, size, padding, padding)
                        .create()
            } else if (itemPosition == 0) {
                return Y_DividerBuilder()
                        .setLeftSideLine(drawFirstLine, colorInt, size, padding, padding)
                        .create()
            } else if (itemPosition < itemCount - 1) {
                return Y_DividerBuilder()
                        .setLeftSideLine(true, colorInt, size, padding, padding)
                        .create()
            } else return Y_DividerBuilder()
                    .setLeftSideLine(true, colorInt, size, padding, padding)
                    .setRightSideLine(drawEndLine, colorInt, size, padding, padding)
                    .create()
        }

    }


    companion object {
        val HORIZONTAL = 0
        val VERTICAL = 1
    }

}